import java.util.ArrayList;

/**
 * @description:
 * @Author: wuzhenbin
 * @CreateTime: 2025/2/15
 */
public class leetcode_101 {
    public static void main(String[] args) {

    }

    public boolean isSymmetric(TreeNode root) {
        ArrayList<Integer> leftList = new ArrayList<>();
        ArrayList<Integer> rightList = new ArrayList<>();
        preorder(root.left,leftList);
        postorder(root.right,rightList);
        if(!leftList.isEmpty() && leftList.equals(rightList)){
            return true;
        }
        return false;
    }

    private void postorder(TreeNode root, ArrayList<Integer> rightList) {
        if(root==null)return;
        rightList.add(root.val);
        postorder(root.right,rightList);
        postorder(root.left,rightList);
    }

    private void preorder(TreeNode root, ArrayList<Integer> leftList) {
        if(root==null)return;
        leftList.add(root.val);
        preorder(root.left,leftList);
        preorder(root.right,leftList);
    }

    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
